<?php

$__FILEPATH__ = dirname(__FILE__)."/";

require_once($__FILEPATH__."../func_common.php");
require_once($__FILEPATH__."../class_def.php");
require_once($__FILEPATH__."../conf/info.php");

CheckAdminAndInitHeader();

if (isset($_POST["add"]) 
	&& isset($_POST["username"]) 
	&& $_POST["username"] != "" 
	&& $_POST["studentnum"] != ""
	&& IsDigitInStr($_POST["studentnum"]))
{
	$ret = false;
	$mysqli = GetMysqliInstance();
	$username = $_POST["username"];
	$studentnum = $_POST["studentnum"];

	$stmt = $mysqli->prepare("select nickname,imagesrc from userlist where username = ?");
	$stmt->bind_param("s", $username);
	$stmt->execute();
	$stmt->bind_result($nickname, $imagesrc);
	if ($stmt->fetch())
	{
			$ret = true;
	}
	$stmt->close();

	

	if ($ret)
	{
		$imagesrc_mini = str_replace("pic", "pic_min", $imagesrc);
		CreateMiniImage(".".$imagesrc, ".".$imagesrc_mini);
		$strsql = "insert into acmerlist(username, nickname, imagesrc, studentnum) values(?, ?, ?, ?)";
		$stmt = $mysqli->prepare($strsql);
		$stmt->bind_param("ssss", $username, $nickname, $imagesrc_mini, $studentnum);
		$ret = ($ret && $stmt->execute());
		$stmt->close();
	}

	$mysqli->close();

	if ($ret)
		echo "添加成功！<br /><a href=\"add_acmer.php\">继续添加</a>";
	else 
        echo "<p style=\"color:red\">添加失败~~</p><a href=\"add_acmer.php\">返回继续</a>";

	exit(0);
}

?>